package com.dpmc.service;

 
import java.util.List;
import java.util.Map; 

import javax.ejb.Stateless;
 
import com.common.util.ObjectUtils;
import com.core.service.AppBaseService;
import com.dpmc.entity.*;

/**
 * 服务类——商品管理
 */
@Stateless
public class SVC_SPGL  extends AppBaseService implements SVC_SPGLRemote, SVC_SPGLLocal {

	@Override
	public Map ADD_FLXX(Map param) {
		TB_SPGL_FLXX bo =  ObjectUtils.mapToJavaBean(param, TB_SPGL_FLXX.class); 
		if(bo.getID()==null){
			bo.setID(bo.uuid());
		}
		if(bo.getSJFL_ID()==null || !bo.getSJFL_ID().isEmpty()){
			bo.setFLLJ(bo.getID());
		}else{
			TB_SPGL_FLXX p_bo = getJpaDao().find(TB_SPGL_FLXX.class, bo.getSJFL_ID());
			bo.setFLLJ(p_bo.getID()+","+bo.getID());
		}
		
		bo.setCREATE_TIME(getOpTime(param));
		bo.setOP_ITEM(getOpTime(param));
		bo.setOPID(getOpid(param));
		bo.setSTATUS(TB_SHGL_LXDY.STATUS_ACTIVITY);
		getJpaDao().save(bo); 
		return ObjectUtils.javaBeanToMap(bo); 
	}

	@Override
	public Map UPD_FLXX(Map param) {
		TB_SPGL_FLXX dto =  ObjectUtils.mapToJavaBean(param, TB_SPGL_FLXX.class); 
		TB_SPGL_FLXX po =getJpaDao().find(TB_SPGL_FLXX.class, dto.getID()); 
		
		if(dto.getSJFL_ID()==null || !dto.getSJFL_ID().isEmpty()){
			dto.setFLLJ(dto.getID());
		}else{
			TB_SPGL_FLXX p_bo = getJpaDao().find(TB_SPGL_FLXX.class, dto.getSJFL_ID());
			dto.setFLLJ(p_bo.getID()+","+dto.getID());
		}
	    
	    ObjectUtils.copyJavaBeanToBean(dto, po, "CREATE_TIME");
	    po.setOP_ITEM(getOpTime(param));
	    po.setOPID(getOpid(param));
	    getJpaDao().update(po); 
	    
	    return ObjectUtils.javaBeanToMap(po);
	}

	@Override
	public void DEL_FLXX(Map param) {
		TB_SPGL_FLXX dto =  ObjectUtils.mapToJavaBean(param, TB_SPGL_FLXX.class); 
		TB_SPGL_FLXX po =getJpaDao().find(TB_SPGL_FLXX.class, dto.getID()); 
		     
		 po.setOP_ITEM(getOpTime(param));
		 po.setOPID(getOpid(param));
		 po.setSTATUS(TB_SHGL_LXDY.STATUS_DEAD);
		 getJpaDao().update(po);  
	}

	@Override
	public Map ADD_SPXX(Map param) {
		TB_SPGL_SPXX bo =  ObjectUtils.mapToJavaBean(param, TB_SPGL_SPXX.class); 
		if(bo.getID()==null){
			bo.setID(bo.uuid());
		} 
		
		bo.setCREATE_TIME(getOpTime(param));
		bo.setOP_ITEM(getOpTime(param));
		bo.setOPID(getOpid(param));
		bo.setSTATUS(TB_SHGL_LXDY.STATUS_ACTIVITY);
		getJpaDao().save(bo); 
		return ObjectUtils.javaBeanToMap(bo); 
	}

	@Override
	public Map UPD_SPXX(Map param) {
		TB_SPGL_SPXX dto =  ObjectUtils.mapToJavaBean(param, TB_SPGL_SPXX.class); 
		TB_SPGL_SPXX po =getJpaDao().find(TB_SPGL_SPXX.class, dto.getID());  
		 
	    ObjectUtils.copyJavaBeanToBean(dto, po, "CREATE_TIME");
	    po.setOP_ITEM(getOpTime(param));
	    po.setOPID(getOpid(param));
	    getJpaDao().update(po); 
	    
	    List<Map> LIST_TB_SPGL_SPXX_SXZ = ObjectUtils.getMapValue(param, "LIST_TB_SPGL_SPXX_SXZ", List.class);
		if(LIST_TB_SPGL_SPXX_SXZ!=null){ 
			for(Map item : LIST_TB_SPGL_SPXX_SXZ){
				TB_SPGL_SPXX_SXZ kzsx =  ObjectUtils.mapToJavaBean(item, TB_SPGL_SPXX_SXZ.class);   
				kzsx.setSPXX_ID(po.getID());
				kzsx.setOP_ITEM(getOpTime(param));
				kzsx.setOPID(getOpid(param));
				if(kzsx.getID()==null){ 
					if( kzsx.getSXZ()!=null&&!kzsx.getSXZ().isEmpty()){
						kzsx.setID(kzsx.uuid()); 
						kzsx.setCREATE_TIME(getOpTime(param)); 
						kzsx.setSTATUS(TB_SHGL_LXDY_KZSX.STATUS_ACTIVITY);
						getJpaDao().save(kzsx); 
						((Map)item).put("ID", kzsx.getID());
					}
				}else{
					TB_SPGL_SPXX_SXZ po_kzsx = getJpaDao().find(TB_SPGL_SPXX_SXZ.class, kzsx.getID());
					ObjectUtils.copyJavaBeanToBean(kzsx, po_kzsx, "CREATE_TIME","STATUS");
					getJpaDao().update(po); 
				}
			}
		}  
	    
	    return ObjectUtils.javaBeanToMap(po);
	}

	@Override
	public void DEL_SPXX(Map param) {
		TB_SPGL_SPXX dto =  ObjectUtils.mapToJavaBean(param, TB_SPGL_SPXX.class); 
		TB_SPGL_SPXX po =getJpaDao().find(TB_SPGL_SPXX.class, dto.getID()); 
		     
		 po.setOP_ITEM(getOpTime(param));
		 po.setOPID(getOpid(param));
		 po.setSTATUS(TB_SHGL_LXDY.STATUS_DEAD);
		 getJpaDao().update(po);  
	}

	@Override
	public Map ADD_FLXX_SXDY(Map param) {
		TB_SPGL_FLXX_SXDY bo =  ObjectUtils.mapToJavaBean(param, TB_SPGL_FLXX_SXDY.class); 
		if(bo.getID()==null){
			bo.setID(bo.uuid());
		} 
		
		bo.setCREATE_TIME(getOpTime(param));
		bo.setOP_ITEM(getOpTime(param));
		bo.setOPID(getOpid(param));
		bo.setSTATUS(TB_SPGL_FLXX_SXDY.STATUS_ACTIVITY);
		getJpaDao().save(bo); 
		return ObjectUtils.javaBeanToMap(bo); 
	}

	@Override
	public Map UPD_FLXX_SXDY(Map param) {
		TB_SPGL_FLXX_SXDY dto =  ObjectUtils.mapToJavaBean(param, TB_SPGL_FLXX_SXDY.class); 
		TB_SPGL_FLXX_SXDY po =getJpaDao().find(TB_SPGL_FLXX_SXDY.class, dto.getID()); 
		
		 
	    ObjectUtils.copyJavaBeanToBean(dto, po, "CREATE_TIME");
	    po.setOP_ITEM(getOpTime(param));
	    po.setOPID(getOpid(param));
	    getJpaDao().update(po); 
	    
	    return ObjectUtils.javaBeanToMap(po);
	}

	@Override
	public void DEL_FLXX_SXDY(Map param) {
		TB_SPGL_FLXX_SXDY dto =  ObjectUtils.mapToJavaBean(param, TB_SPGL_FLXX_SXDY.class); 
		TB_SPGL_FLXX_SXDY po =getJpaDao().find(TB_SPGL_FLXX_SXDY.class, dto.getID()); 
		     
		 po.setOP_ITEM(getOpTime(param));
		 po.setOPID(getOpid(param));
		 po.setSTATUS(TB_SPGL_FLXX_SXDY.STATUS_DEAD);
		 getJpaDao().update(po);  
	} 
 
}
